package com.rw.engine.permission.exception;

import com.rw.engine.CommonExceptionResolver;
import com.rw.engine.util.ResponseUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 权限模块的异常处理器
 */
public class PermissionExceptionResolve extends CommonExceptionResolver<PermissionException> {
    public PermissionExceptionResolve() {
        super(PermissionException.class);
    }

    @Override
    public ModelAndView resolveTargetException(HttpServletRequest request, HttpServletResponse response, Object handler,
                                               PermissionException ex) {
        // 设置状态码
        response.setStatus(HttpStatus.FORBIDDEN.value());
        ResponseUtil.writeResponse(response, ex.getMessage());
        return new ModelAndView();
    }
}
